# datetime : 22/9/2024 上午10:05
# -*-coding : utf-8 -*-
# Author : 油条测试
from operate.operate_excel import Operate_Excel
from data.config_data import Config_col
from operate.operate_json import Operate_Json


class GetData():
    def __init__(self):
        self.data = Operate_Excel()
        self.col = Config_col()
        self.json = Operate_Json()

    ##获取exl表格行数
    def get_nrows(self):
        return self.data.get_rows()

    # 获取接口名称
    def get_interfaceName(self, row):
        col = self.col.get_interfaceName_col()
        return self.data.read_cell_values(row, col)

    # 获取接口地址
    def get_url(self, row):
        col = self.col.get_url_col()
        return self.data.read_cell_values(row, col)

    # 是否执行
    def isExcute(self, row):
        col = self.col.get_isExecute_col()
        isExcute = self.data.read_cell_values(row, col)
        if isExcute == 'yes':
            return True
        else:
            return False

    # 请求方式
    def get_requestsMethod(self, row):
        col = self.col.get_requestsMethod_col()
        return self.data.read_cell_values(row, col)

    # 是否携带请求头
    def get_isHearders(self, row):
        col = self.col.get_isHeaders_col()
        isHeader = self.data.read_cell_values(row, col)
        if isHeader == 'yes':
            return True
        else:
            return False

    # 是否是json数据
    def isJsonData(self, row):
        col = self.col.get_isJson_col()
        isJson = self.data.read_cell_values(row, col)
        if isJson == 'yes':
            return True
        else:
            return False

    # 获取请求数据
    def get_requestsData(self, row):
        col = self.col.get_requestsData_col()
        return self.data.read_cell_values(row, col)

    # 获取json数据
    def get_JsonData(self, row):
        key = self.get_requestsData(row)
        return self.json.read_value_by_key(key)

    # 获取预期结果
    def get_exceptRes(self, row):
        col = self.col.get_exceptRes_col()
        return self.data.read_cell_values(row, col)

    # 获取实际结果
    def get_actualsRes(self, row):
        col = self.col.get_actalsRes_col()
        return self.data.read_cell_values(row, col)

    # 获取请求头信息
    def get_herders(self):
        return self.col.get_herders()

    # 写入数据到exl
    def write_value(self, row, value):
        col = self.col.get_actalsRes_col()
        self.data.input_value(row, col, value)
